﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Entities;
using Domain.Core;
using Domain.Core.Specification;
using Domain.Core.Extensions;
using System.Data.Objects;
namespace Domain.Service.System
{
    /// <summary>
    /// 用户领域的业务
    /// </summary>
    public class UserService : Domain.Service.System.IUserService
    {
        IUserRepository _webManageUsers;
        /// <summary>
        /// 这个IUserRepository对象实例是从WEB层传递进来的
        /// </summary>
        /// <param name="webManageUsers"></param>
        public UserService(IUserRepository webManageUsers)
        {
            if (webManageUsers == (IUserRepository)null)
                throw new ArgumentNullException("对象为NULL");
            _webManageUsers = webManageUsers;
        }


        /// <summary>
        /// 所有用户
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public List<WebManageUsers> GetWebManageUsers(UserListSpecification userListSpecification)
        {
            var linq = _webManageUsers.GetWebManageUsers(userListSpecification)
                                     .Include(i => i.WebManageRoles)
                                     .Select(i => new WebManageUsers_Ext
                                     {
                                         CreateDate = i.CreateDate,
                                         ManageUserID = i.ManageUserID,
                                         RealName = i.RealName,
                                         LoginName = i.LoginName,
                                         Email = i.Email,
                                         Mobile = i.Mobile,
                                         WebSystemID = i.WebSystemID,
                                         WebManageRoles = i.WebManageRoles,
                                     });

            return linq.ToList<WebManageUsers>();
        }
        /// <summary>
        /// 活跃用户
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public List<WebManageUsers> GetActiveUsers(UserActiveSpecification userActiveSpecification)
        {
 
            //query repository
            return _webManageUsers.GetEntities(userActiveSpecification)
                                 .OrderByDescending(i => i.UpdateDate)
                                 .ToList();
        }
    }
}
